package com.zy.mc_module.ui.micang.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.market.sdk.utils.CollectionUtils;
import com.zy.mc_module.base.kotlin.BaseFragment;
import com.zy.mc_module.databinding.BaseListViewBinding;
import com.zy.mc_module.databinding.FragmentMineBinding;
import com.zy.mc_module.databinding.ItemActiveDetailBinding;
import com.zy.mc_module.mvp.bean.RiceStoreHouseBean;
import com.zy.mc_module.ui.micang.RiceContract;
import com.zy.mc_module.ui.micang.RicePresenter;
import com.zy.mc_module.ui.micang.adapter.MineRiceAdapter;
import com.zy.mc_module.utils.retrofit.error.ThdException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MineRiceFragment extends BaseFragment<RiceContract.View, RicePresenter, BaseListViewBinding> implements RiceContract.View {
    @NonNull
    @Override
    public BaseListViewBinding getViewBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) {
        return BaseListViewBinding.inflate(inflater, container, false);
    }

    @Override
    protected void isLoadSir(@NonNull Object... objects) {
        super.isLoadSir(true, binding.refreshLayout.getId());
    }

    @Nullable
    @Override
    protected RicePresenter createPresenter() {
        return new RicePresenter();
    }

    public static MineRiceFragment getInstance(int index) {
        MineRiceFragment fragment = new MineRiceFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("index", index);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected void LazyLoad() {
        getPresenter().riceStoreHouseFindAll(getContext());
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {

        initRefresh(binding.refreshLayout, binding.recycleView);
        MineRiceAdapter adapter = new MineRiceAdapter(new ArrayList<>());
        binding.recycleView.setLayoutManager(new LinearLayoutManager(getContext()));
        binding.recycleView.setAdapter(adapter);
    }

    @Override
    public void onError(ThdException error) {

    }

    @Override
    public <T> void onSuccess(T t, int type) {
        if (type == RicePresenter.RICE_STORE_HOUSE) {
            List<RiceStoreHouseBean> riceStoreHouseBeanList = (List<RiceStoreHouseBean>) t;
            refreshComplete(riceStoreHouseBeanList);
            showEmpty(riceStoreHouseBeanList);
        }
    }

    @Override
    public void onError(ThdException error, int type) {

        showError();
    }
}
